TreeView Control - Removing Nodes

Removing Nodes

To remove an node, you either need to know its Index or its unique key (if you gave it one). Then you use the following syntax:

TreeView1.Nodes.Remove IndexOrKey

The following example first removes a node which key is "root", and then removes a node which key is 12.

TreeView1.Nodes.Remove "root"
TreeView1.Nodes.Remove 12

Note that if a node has sub items when it is removed, all its sub items are removed too.

If you want to remove all the nodes in the TreeView, you can use the Clear method:

TreeView1.Nodes.Clear

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.